#include "semantic.h"
#include "symboltable.h"
#include "typechecker.h"
#include <iostream>
#include <boost/foreach.hpp>

#define foreach BOOST_FOREACH

SemanticAnalyser::SemanticAnalyser(shared_ptr<Program> program) : program(program) { }

SemanticAnalyser::~SemanticAnalyser() {
}

void SemanticAnalyser::checkProgram() {
	TypeChecker checker(program);
	checker.check();

	if(checker.hasErrors()) {
		foreach(std::string error, checker.getErrors()) std::cout << error << std::endl;
	}
}

bool SemanticAnalyser::hasErrors() {
	return !(errors.empty());
}

void SemanticAnalyser::printErrors() {
	if(hasErrors()) {
		for(unsigned int i = 0; i < errors.size(); i++) {
			std::cout << errors[i] << std::endl;
		}
	}
}
